<!-- components/AddBook.vue -->
<template>

  <div id="app">
    <el-form ref="form" :model="form" label-width="80px">
      <el-form-item label="ID">
        <el-input v-model="form.id"></el-input>
      </el-form-item>
      <el-form-item label="书名">
        <el-input v-model="form.bookname"></el-input>
      </el-form-item>
            <el-form-item label="作者">
        <el-input v-model="form.author"></el-input>
      </el-form-item>
            <el-form-item label="复制次数">
        <el-input v-model="form.copies"></el-input>
      </el-form-item>
      <!-- 注意：其他字段如author, price等也应包含在表单中 -->
      <el-button type="primary" plain @click="onSubmit">立即创建</el-button>
    </el-form>
  </div>
</template>

<script>
export default {
  data() {
    return {
      form: {
        id: '',
        bookname: '',
        author: '',
        price: '',
        date1: ''
      }
    };
  },
  methods: {
    onSubmit() {
      this.$store.dispatch('addBookToStore', this.form).then(() => {
        this.$message({
          message: '创建成功',
          type: 'success'
        });
        this.form = { // 清空表单
          id: '',
          bookname: '',
          author: '',
          price: '',
          date1: ''
        };
      }).catch((error) => {
        this.$message.error('创建失败：' + error.message);
      });
    }
  }
};
</script>